package com.etlmaster.rowprocessor.core;

import java.util.Map;

import com.etlmaster.executor.trans.core.Line;
import com.etlmaster.executor.utils.LogWriter;
import com.etlmaster.rowprocessor.disruptor.readEvent.LineEvent;



/**
 * @author Larry
 * @copyright Larry@etlMaster
 * @since 2017-09-10
 */
public abstract class AbstractWriter extends AbstractPlugin implements
		AbstractInputPlugin {
	private String inputStreamId;

	public AbstractWriter(String id, String jobId, String name, String code,
			Map<String, Object> paramMap, Map<String, Object> var) {
		super(id, jobId, name, code, paramMap, var);
	}

	public abstract void read(Line line);

	public String getInputStreamId() {
		return inputStreamId;
	}

	public void setInputStreamId(String inputStreamId) {
		this.inputStreamId = inputStreamId;
	}

	@Override
	public void onEvent(LineEvent event, long sequence, boolean endOfBatch)
			throws Exception {
		try {
			read(event.getValue());
			this.setCounter(sequence);
			LogWriter.addLog(this.getJobId(), 0, "debug", "writer:{} sequence:"
					+ sequence, this.getName());
		} catch (Exception e) {
			LogWriter.addLog(getJobId(), 0, "ERROR",e.getMessage());
			e.printStackTrace();
		}
	}

}
